package com.github.benmanes.caffeine.demo.Population;

import com.github.benmanes.caffeine.cache.AsyncCache;
import com.github.benmanes.caffeine.cache.Caffeine;

import java.util.concurrent.CompletableFuture;

public class DemoAsynchronous {
    static System.Logger logger = System.getLogger(DemoAsynchronous.class.getName());

    public static void hello(String[] args) {
        System.out.println("args = " + args);
    }


    public static void main(String... args) throws Exception {
        AsyncCache<String, String> cache = Caffeine.newBuilder().buildAsync();


        String key = "疯狂创客圈";

        //会返回一个 future对象， 调用future对象的get方法会一直卡住直到得到返回，和多线程的submit一样
        CompletableFuture<String> future = cache.get(key, k -> {
            System.out.println("key:" + k);
            return "一个高并发 研究社群";
        });
        String val = future.get();
        System.out.println(val);

    }

}
